﻿Public Class Frm_Rech_khabir

    Private Sub Frm_Rech_khabir_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_khabir.Enabled = True
        Frm_idafat_9da2i.Enabled = True
    End Sub

    Private Sub Frm_Rech_khabir_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comb_matorido_elbaht.SelectedIndex = 0
    End Sub

    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Try
            List_tous.Items.Clear()
            Partager.list_recherch.Clear()
            If comb_matorido_elbaht.SelectedItem = "الاسم العائلي" Then
                For Each av As Khabir In Partager.moi.List_khabir
                    If av.Nom.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Nom, av.Prenom, av.Prenom}))

                    End If

                Next


            ElseIf comb_matorido_elbaht.SelectedItem = "الاسم الشخصي" Then

                For Each av As Khabir In Partager.moi.List_khabir
                    If av.Prenom.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Nom, av.Prenom, av.Prenom}))

                    End If

                Next
 


            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If txt_rech.Text = "" Then
            List_tous.Items.Clear()
        End If
    End Sub

    
    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click

        If List_tous.SelectedIndices.Count > 0 Then
            Dim avo As Khabir
            Dim j As Integer = 0
            Try
                For Each i As Integer In List_tous.SelectedIndices
                    avo = Partager.list_recherch(i)
                    If Partager.type = "Frm_idafat_9da2i" Then

                        Frm_idafat_9da2i.Comb_khabir.Text = avo.Nom & "  " & avo.Prenom
                    
                    Else
                        For Each khib As Khabir In Partager.moi.List_khabir
                            If avo.Id = khib.Id Then
                                Frm_khabir.List_tous.Items(j).Focused = True
                                Frm_khabir.List_tous.Items(j).Selected = True
                            End If
                            j += 1
                        Next
                    End If
                Next

        Me.Close()
            Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Else
        MsgBox("اختر خبير من القائمة", MsgBoxStyle.Information, "خطأ في البحث")
        End If
    End Sub

    Private Sub comb_matorido_elbaht_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comb_matorido_elbaht.SelectedIndexChanged
        txt_rech.Clear()
    End Sub
End Class